#对barracuda数据进行轴向处理
#by zyp
import numpy as np
import pandas as pd
import matplotlib
import matplotlib.pyplot as plt
import math
n=66
name_data='data34__31'

name=np.array(pd.read_csv(name_data,nrows=n+1))
#读取dat文件数据
real_data=5     #从第j个开始是物理数据
look_data= 41   #想看哪个数据
data=np.loadtxt(name_data,skiprows=n+2)
total_rows=data.shape[0]
total_cols=data.shape[1]
data=data[data[:,n-2].argsort()]       #高度从小到大


####轴向######
y_max_cell=max(data[:,2])     #高度上共有几个网格
y_row=5     #几层网格合一
point_number=int(round(y_max_cell/y_row))
y_min=min(data[:,n-2])
y_max=max(data[:,n-2])
interval=(y_max-y_min)/(point_number-1)
result=np.zeros((point_number,n-6))
result[:,0]=np.linspace(y_min,y_max,point_number)
interval_use=interval/2


j=real_data-1
while j<n-3:
    print(name[j+1])
    i=0
    k=0
    sum=0
    count=0
    while i<total_rows:
        if result[k,0]-interval_use<data[i,n-2]<=result[k,0]+interval_use:
            sum=sum+data[i,j]
            count+=1
            i+=1
        else:
            aver=sum/count
            result[k,j-3]=aver
            k+=1
            sum=0
            count=0
    result[k,j-3]=aver
    j+=1


np.savetxt(name_data+'.csv',result,delimiter=',')
plt.plot(result[:,look_data-4],result[:,0])
plt.title(name[look_data])
plt.show()